<?php

require_once('txt_excel.helper.php');

$CSV = "voc2.txt";

$f = fopen($CSV,'r');
$lastword = "";

$json = array();
$lastjsonentry = array();

while ($row = TxtExcelHelper::getNextRow($f)) {
	
	$word = $row[0];
	$translation = $row[1];
	$newtranslation = true;
	
	if ($row[0] == "") {
		$newtranslation = false;
	}
	
	if ($newtranslation) {
		if (!empty($lastjsonentry)) {
			$json[] = $lastjsonentry;
		}
		$lastjsonentry = array(
			'word' => $word,
			'translation' => $translation
		);
	} else {
		if (!is_array($lastjsonentry['translation'])) {
			$lastjsonentry['translation'] = array($lastjsonentry['translation']);
		}
		
		$lastjsonentry['translation'][] = $translation;
	}
	
	$subtranslation = null;
}

echo "<pre>";
print_r($json);

file_put_contents("voc.js", json_encode($json));
?>